/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include "basic_def.h"
#include "basic_vec.h"






Inline int32 f_JIT_单值整数计算(int32* v1, int32* v2, uint8 CalType) {
	int32 r;
	switch (CalType) {
		case 0: r = int32(v1[0]) + int32(v2[0]); break;
		case 1: r = int32(v1[0]) - int32(v2[0]); break;
		case 2: r = int32(v1[0]) * int32(v2[0]); break;
		case 3: r = int32(v1[0]) / int32(DEF_Max(v2[0],1)); break;
		case 4: {
			break;
		}
		case 5: {
			break;
		}
		case 6: {

			break;
		}
		case 7: {
			break;
		}
	}
	return r;
}




Inline uint32 f_JIT_坐标转索引(const ivec3& 坐标, const ivec3& 分辨率, uint8 CalType) {
	uint32 r;
	switch (CalType) {
		case 0 : {
			return (分辨率.x * 分辨率.y) * 坐标.z + 分辨率.x * 坐标.y + 坐标.x;
		}
		case 1: {
			return (分辨率.x * 分辨率.z) * 坐标.y + 分辨率.x * 坐标.z + 坐标.x;
		}
		case 2: {
			return (分辨率.y * 分辨率.z) * 坐标.x + 分辨率.y * 坐标.z + 坐标.x;
		}
	}
	return r;
}

Inline void f_JIT_坐标转索引m(const S_iVec3Array* 坐标, const S_iVec3Array* 分辨率, S_UI32Array* 索引, uint8 CalType) {
	uint32 num = DEF_Max(坐标->count, 分辨率->count);

	f_core_array_resize((S_Array*)索引, num);

	bool 坐标多例 = 坐标->count >= num;
	bool 分辨率多例 = 分辨率->count >= num;

	for (uint32 i = 0; i < num; ++i) {
		uint32 index = f_JIT_坐标转索引(坐标多例 ? 坐标->ptr_userData[i] : 坐标->ptr_userData[0], 分辨率多例 ? 分辨率->ptr_userData[i] : 分辨率->ptr_userData[0], CalType);
		索引->ptr_userData[i] = index;
	}
}

Inline ivec3 f_JIT_索引转坐标(const uint32 index, const ivec3& 分辨率, uint8 CalType) {
	ivec3 r;
	switch (CalType) {
		case 0: {
			uint32 层 = 分辨率.x * 分辨率.y;
			r.z = index / DEF_Max(层,1);
			层 *= r.z;
			r.y = (index - 层) / DEF_Max(分辨率.x,1);
			r.x = index - (层 + r.y * 分辨率.x);
			break;
		}
		case 1: {
		
			break;
		}
		case 2: {

			break;
		}
	}
	return r;
}

Inline void f_JIT_索引转坐标m(const S_UI32Array* 索引, const S_iVec3Array* 分辨率, S_iVec3Array* 坐标, uint8 CalType) {
	uint32 num = DEF_Max(索引->count, 分辨率->count);

	f_core_array_resize((S_Array*)坐标, num);

	bool 坐标多例 = 索引->count >= num;
	bool 分辨率多例 = 分辨率->count >= num;

	for (uint32 i = 0; i < num; ++i) {
		ivec3 c = f_JIT_索引转坐标(坐标多例 ? 索引->ptr_userData[i] : 索引->ptr_userData[0], 分辨率多例 ? 分辨率->ptr_userData[i] : 分辨率->ptr_userData[0], CalType);
		坐标->ptr_userData[i] = c;
	}
}




















